# -*- coding: utf-8 -*-
# @Time    : 2021/4/28 9:27
# @Author  : Zhangrenjie
# @Email   : zhangrenjie1998@163.com
# @File    : 高阶函数.py
# @Software: PyCharm

"""
 利用map批量检测用户名是否符合规范=> username符合规范, username不符合规范
• 只能包含数据、字母、下划线，不以数字开头，长度在6-18之间
 filter把合法的用户名显示出来
 匿名函数+reduce实现 1*2*3*...*n
 filter函数:找出[1-100]能被3整除的数
 map函数:求list[1-10]各项的平方
 将列表[1,4,5,9] 转换成 '1459'的字符串
"""

import string
import re

# # 随机生成密码个数
# n = int(input("个数"))
# # 密码列表
# passwd_list = []
# for i in range(n):
#     passwd = input()
#     passwd_list.append(''.join(passwd))
#
# print(passwd_list)
# result = list(map(lambda x:(6<=len(x)<=18) and (x[0] not in string.digits) and (re.findall(r'[^\w_]',x) == []), passwd_list))
# check = dict()
# for i in range(n):
#     check[passwd_list[i]] = result[i]
#
# print(check)
# print(list(filter(lambda x: x[1], check.items())))

from functools import reduce
result = reduce(lambda a,b: a*b,range(1,11))
print(result)

print(list(filter(lambda x: x % 3 == 0, range(1, 101))))

print(list(map(lambda x: x * x, range(1, 11))))
from functools import reduce

print(reduce(lambda a, b: str(a) + str(b), [1,4,5,9]))

list1 = [7, -8, 5, 4, 0, -2, -5]
# print(sorted(list1,key=lambda x: x>0 ,reverse=True))
# print(sorted(list1))
# print(sorted(list1,key=lambda x:x<0,reverse=True))
print(sorted(list1, key=lambda x: (x < 0, abs(x))))

s = 'asdf234GDSdsf23'
print(''.join(sorted(s, key=lambda x: (x.isdigit(), x.isdigit() and int(x) % 2 == 0, x.isupper(), x))))